unit untListagemMarca;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, untListagemPadrao, DB, Grids, DBGrids, StdCtrls, Buttons,
  ExtCtrls;

type
  TfrmListagemMarca = class(TfrmListagemPadrao)
    procedure btnIncluirClick(Sender: TObject);
    procedure btnAlterarClick(Sender: TObject);
    procedure btnExcluirClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmListagemMarca: TfrmListagemMarca;

implementation

uses untListagemCidade, UntDm, untMarca;

{$R *.dfm}

procedure TfrmListagemMarca.btnIncluirClick(Sender: TObject);
begin
  inherited;
  frmCadMarca.Tag := 1;
  frmCadMarca.ShowModal;
end;

procedure TfrmListagemMarca.btnAlterarClick(Sender: TObject);
begin
  inherited;
  if DM.CDSMarca.RecordCount = 0 then
  begin
    frmCadMarca.Tag := 1;
    frmCadMarca.ShowModal;
  end else begin
    frmCadMarca.Tag := 2;
    frmCadMarca.ShowModal;
  end;

end;

procedure TfrmListagemMarca.btnExcluirClick(Sender: TObject);
begin
  inherited;


  // -----efetua a exclusao do registro_____________\\\\\\\\\\\\
  if DM.CDSMarca.RecordCount = 0 then
    Exit;
  try
    if MessageDlg('Deseja Excluir a Marca?', mtConfirmation, [mbYes,mbNo],0) = mrYes then
    begin
      DM.SDSComando.CommandText := 'DELETE FROM MARCA WHERE COD_MARCA = :COD_MARCA';
      DM.SDSComando.Params.ParamByName('COD_MARCA').AsString := DM.CDSMarca.FieldByName('COD_MARCA').AsString;
      DM.SDSComando.ExecSQL();
      DM.CDSMarca.Close;
      DM.CDSMarca.Open;
    end;
  except
    if MessageDlg('Impossivel Excluir a Marca', mtError, [mbOK],0) = mrOK then
      Exit;
  end;


end;

procedure TfrmListagemMarca.FormShow(Sender: TObject);
begin
  inherited;
  DM.CDSMarca.Open;
end;

procedure TfrmListagemMarca.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  DM.CDSMarca.Open;
end;

end.
